gl path "~/Dropbox/CovidTurnout/replication"

// declare dependencies

use "$path/original_data/analysis_file.dta", clear
keep if inlist(age, 64, 65)

* Turnout
reg voted age65_2020 is2020 age65_2018 is2018 age65_2016 is2016 age65_2014 is2014 age65_2012 [fw=obs], r
local b1 = _b[age65_2012]
local se1 = _se[age65_2012]
local n1 = e(N)
local ba1 = _b[age65_2020]
local sea1 = _se[age65_2020]
local bi1 = _b[is2020]
local sei1 = _se[is2020]
local ba181 = _b[age65_2018]
local sea181 = _se[age65_2018]
local bi181 = _b[is2018]
local sei181 = _se[is2018]
local ba161 = _b[age65_2016]
local sea161 = _se[age65_2016]
local bi161 = _b[is2016]
local sei161 = _se[is2016]
local ba141 = _b[age65_2014]
local sea141 = _se[age65_2014]
local bi141 = _b[is2014]
local sei141 = _se[is2014]
local c1 = _b[_cons]

* Absentee 
reg absentee age65_2020 is2020 age65_2018 is2018 age65_2016 is2016 age65_2014 is2014 age65_2012 [fw=obs], r
local b3 = _b[age65_2012]
local se3 = _se[age65_2012]
local n3 = e(N)
local ba3 = _b[age65_2020]
local sea3 = _se[age65_2020]
local bi3 = _b[is2020]
local sei3 = _se[is2020]
local ba183 = _b[age65_2018]
local sea183 = _se[age65_2018]
local bi183 = _b[is2018]
local sei183 = _se[is2018]
local ba163 = _b[age65_2016]
local sea163 = _se[age65_2016]
local bi163 = _b[is2016]
local sei163 = _se[is2016]
local ba143 = _b[age65_2014]
local sea143 = _se[age65_2014]
local bi143 = _b[is2014]
local sei143 = _se[is2014]
local c3 = _b[_cons]

* Early Voting
reg early age65_2020 is2020 age65_2018 is2018 age65_2016 is2016 age65_2014 is2014 age65_2012 [fw=obs], r
local b5 = _b[age65_2012]
local se5 = _se[age65_2012]
local n5 = e(N)
local ba5 = _b[age65_2020]
local sea5 = _se[age65_2020]
local bi5 = _b[is2020]
local sei5 = _se[is2020]
local ba185 = _b[age65_2018]
local sea185 = _se[age65_2018]
local bi185 = _b[is2018]
local sei185 = _se[is2018]
local ba165 = _b[age65_2016]
local sea165 = _se[age65_2016]
local bi165 = _b[is2016]
local sei165 = _se[is2016]
local ba145 = _b[age65_2014]
local sea145 = _se[age65_2014]
local bi145 = _b[is2014]
local sei145 = _se[is2014]
local c5 = _b[_cons]

* Election Day
reg precinct age65_2020 is2020 age65_2018 is2018 age65_2016 is2016 age65_2014 is2014 age65_2012 [fw=obs], r
local b7 = _b[age65_2012]
local se7 = _se[age65_2012]
local n7 = e(N)
local ba7 = _b[age65_2020]
local sea7 = _se[age65_2020]
local bi7 = _b[is2020]
local sei7 = _se[is2020]
local ba187 = _b[age65_2018]
local sea187 = _se[age65_2018]
local bi187 = _b[is2018]
local sei187 = _se[is2018]
local ba167 = _b[age65_2016]
local sea167 = _se[age65_2016]
local bi167 = _b[is2016]
local sei167 = _se[is2016]
local ba147 = _b[age65_2014]
local sea147 = _se[age65_2014]
local bi147 = _b[is2014]
local sei147 = _se[is2014]
local c7 = _b[_cons]


/* 
 * Indiana data
 */ 

use "$path/original_data/analysis_file_indiana.dta", clear
keep if inlist(age, 64, 65)

// turnout
reg voted age65_2020 is2020 age65_2018 [fw=obs], r
local n2 = e(N)
local ba2 = _b[age65_2020]
local sea2 = _se[age65_2020]
local bi2 = _b[is2020]
local sei2 = _se[is2020]
local ba182 = _b[age65_2018]
local sea182 = _se[age65_2018]
local c2 = _b[_cons]


/* reghdfe voted age65_2020 age65_2018 [fw=obs], ///
	a(i.c#i.year) vce(robust)
local ba2 = _b[age65_2020]
local sea2 = _se[age65_2020]
local ba182 = _b[age65_2018]
local sea182 = _se[age65_2018]
 */

	
// absentee
keep if year == 2020

reg absentee age65_2020 [fw=obs], r
local n4 = e(N)
local ba4 = _b[age65_2020]
local sea4 = _se[age65_2020]
local c4 = _b[_cons]
local sec4 = _se[_cons]

/* 
reghdfe absentee age65_2020 [fw=obs], ///
	a(i.c#i.year) vce(robust)
local ba4 = _b[age65_2020]
local sea4 = _se[age65_2020]
local n4 = e(N) */

// early in person
reg early age65_2020 [fw=obs], r
local n6 = e(N)
local ba6 = _b[age65_2020]
local sea6 = _se[age65_2020]
local c6 = _b[_cons]
local sec6 = _se[_cons]

/* reghdfe early age65_2020 [fw=obs], ///
	a(i.c#i.year) vce(robust)
local ba6 = _b[age65_2020]
local sea6 = _se[age65_2020]
local n6 = e(N) */
	
// election day
reg precinct age65_2020 [fw=obs], r
local n8 = e(N)
local ba8 = _b[age65_2020]
local sea8 = _se[age65_2020]
local c8 = _b[_cons]
local sec8 = _se[_cons]


/* reghdfe precinct age65_2020 [fw=obs], ///
	a(i.c#i.year) vce(robust)
local ba8 = _b[age65_2020]
local sea8 = _se[age65_2020]
local n8 = e(N) */


quietly {
	cap log close
	set linesize 255

	log using "$path/output/main_table_combined.tex", text replace
	
	noisily dis "\begin{table}[t]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effect of No-Excuse Absentee Voting on Turnout and Vote Mode, Texas and Indiana General Elections.} \label{tab:main}}"
	noisily dis "\resizebox{1\textwidth}{!}{"
	noisily dis "\begin{tabular}{lcccccccc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{2}{c}{\textbf{Overall Turnout}} & \multicolumn{2}{c}{\textbf{Absentee Voting}} & \multicolumn{2}{c}{\textbf{Early In-Person}} & \multicolumn{2}{c}{\textbf{Election Day In-Person}}\\"
	noisily dis " & \multicolumn{2}{c}{Pr(Voted)[0-100\%]} & \multicolumn{2}{c}{Pr(Absentee)[0-100\%]} & \multicolumn{2}{c}{Pr(Early)[0-100\%]} & \multicolumn{2}{c}{Pr(Elec. Day)[0-100\%]} \\[2mm]"
	noisily dis " & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\"
	noisily dis " State & TX & IN & TX & IN & TX & IN & TX & IN \\"
	noisily dis "\midrule"
	noisily dis "No-Excuse (Age=65) $\times$ 2020 & \textbf{" %5.2f `ba1' "} & \textbf{" %5.2f `ba2' "} & \textbf{" %5.2f `ba3' "} & \textbf{" %5.2f `ba4' "} & \textbf{" %5.2f `ba5' "} & \textbf{" %5.2f `ba6' "} & \textbf{" %5.2f `ba7' "} & \textbf{" %5.2f `ba8' "} \\"
	noisily dis " & (" %3.2f `sea1' ") & (" %3.2f `sea2' ") & (" %3.2f `sea3' ") & (" %3.2f `sea4' ") & (" %3.2f `sea5' ") & (" %3.2f `sea6' ") & (" %3.2f `sea7' ") & (" %3.2f `sea8' ") \\[2mm]"
	noisily dis "No-Excuse (Age=65) $\times$ 2018 & " %5.2f `ba181' " & " %5.2f `ba182' "  & " %5.2f `ba183' " & " %5.2f `ba184' " & " %5.2f `ba185' " & " %5.2f `ba186' "  & " %5.2f `ba187' " & " %5.2f `ba188' " \\"
	noisily dis " & (" %3.2f `sea181' ") & (" %3.2f `sea182' ")  & (" %3.2f `sea183' ") &  & (" %3.2f `sea185' ") &  & (" %3.2f `sea187' ") &  \\[2mm]"
	noisily dis "No-Excuse (Age=65) $\times$ 2016 & " %5.2f `ba161' " & " %5.2f `ba162' "  & " %5.2f `ba163' " & " %5.2f `ba164' " & " %5.2f `ba165' " & " %5.2f `ba166' "  & " %5.2f `ba167' " & " %5.2f `ba168' " \\"
	noisily dis " & (" %3.2f `sea161' ") &   & (" %3.2f `sea163' ") &   & (" %3.2f `sea165' ") &  & (" %3.2f `sea167' ") &  \\[2mm]"
	noisily dis "No-Excuse (Age=65) $\times$ 2014 & " %5.2f `ba141' " & " %5.2f `ba142' "  & " %5.2f `ba143' " & " %5.2f `ba144' " & " %5.2f `ba145' " & " %5.2f `ba146' "  & " %5.2f `ba147' " & " %5.2f `ba148' " \\"
	noisily dis " & (" %3.2f `sea141' ") &   & (" %3.2f `sea143' ") &   & (" %3.2f `sea145' ") &  & (" %3.2f `sea147' ") &  \\[2mm]"
	noisily dis "No-Excuse (Age=65) $\times$ 2012 & " %5.2fc `b1' " & " %5.2fc `b2' " & " %5.2fc `b3' " & " %5.2fc `b4' "  & " %5.2fc `b5' " & " %5.2fc `b6' " & " %5.2fc `b7' " & " %5.2fc `b8' " \\"
	noisily dis " & (" %3.2f `se1' ") & & (" %3.2f `se3' ") &  & (" %3.2f `se5' ") & & (" %3.2f `se7' ") &  \\[2mm]"
	noisily dis "2020 & " %5.2f `bi1' " & " %5.2f `bi2' " & " %5.2f `bi3' " & " %5.2f `bi4' " & " %5.2f `bi5' " & " %5.2f `bi6' " & " %5.2f `bi7' " & " %5.2f `bi8' " \\"
	noisily dis " & (" %3.2f `sei1' ") & (" %3.2f `sei2' ") & (" %3.2f `sei3' ") &  & (" %3.2f `sei5' ") &  & (" %3.2f `sei7' ") & \\[2mm]"
	noisily dis "2018 & " %5.2f `bi181' " & " %5.2f `bi182' " & " %5.2f `bi183' " & & " %5.2f `bi185' " & & " %5.2f `bi187' " & \\"
	noisily dis " & (" %3.2f `sei181' ") &  & (" %3.2f `sei183' ") & & (" %3.2f `sei185' ") & & (" %3.2f `sei187' ") & \\[2mm]"
	noisily dis "2016 & " %5.2f `bi161' " & & " %5.2f `bi163' " & & " %5.2f `bi165' " & & " %5.2f `bi167' " & \\"
	noisily dis " & (" %3.2f `sei161' ") & & (" %3.2f `sei163' ") & & (" %3.2f `sei165' ") & & (" %3.2f `sei167' ") & \\[2mm]"
	noisily dis "2014 & " %5.2f `bi141' " & & " %5.2f `bi143' " & & " %5.2f `bi145' " & & " %5.2f `bi147' " & \\"
	noisily dis " & (" %3.2f `sei141' ") & & (" %3.2f `sei143' ") & & (" %3.2f `sei145' ") & & (" %3.2f `sei147' ") & \\[2mm]"
	noisily dis "Intercept (mean) & " %5.2f `c1' " & " %5.2f `c2' " & " %5.2f `c3' " & " %5.2f `c4' "  & " %5.2f `c5' " & " %5.2f `c6' "  & " %5.2f `c7' " & " %5.2f `c8' " \\"
    noisily dis "Intercept Year & 2012 & 2018 & 2012 & 2020 & 2012 & 2020 & 2012 & 2020 \\[2mm]"
	noisily dis " \# Obs & " %12.0fc `n1' " & " %12.0fc `n2' " & " %12.0fc `n3' " & " %12.0fc `n4' " & " %12.0fc `n5' " & " %12.0fc `n6' " & " %12.0fc `n7' " & " %12.0fc `n8' " \\"
// 	noisily dis " County-by-Age FE & N & Y & N & Y & N & Y & N & Y \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{9}{p{1.3\textwidth}}{\footnotesize Robust standard errors in parentheses. "
	noisily dis "Unit of observation is an individual by year. Indianans and Texans aged 64 or younger who are eligible to vote"
	noisily dis " must provide a valid excuse if they wish to vote absentee. Those aged 65 or older who are eligible to vote can vote absentee without an excuse. Data on turnout and vote mode in Texas covers all presidential and midterm year elections between 2012 and 2020. Data on turnout in Indiana covers the 2018 and 2020 elections. Data on different vote modes in Indiana only covers the 2020 election.}"
	noisily dis "\end{tabular}}"
	noisily dis "\end{table}"
	
	log off

}







